package gang.com.mobelhelper;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import gang.com.mobelhelper.di.component.AppCompent;
import gang.com.mobelhelper.ui.activity.BaseActivity;
import gang.com.mobelhelper.ui.adapter.ViewPagerAdapter;

/**
 * Design设计中TabLayout的使用
 * 沉浸式状态栏 Github地址：https://github.com/jgilfelt/SystemBarTint
 */
public class MainActivity extends BaseActivity {

    @BindView(R.id.drawlayout)
    DrawerLayout drawlayout;
    @BindView(R.id.navigationview)
    NavigationView navigationview;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    private View headview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int setLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void setupActivityComponent(AppCompent appCompent) {

    }

    @Override
    public void init() {
        initDrawerLayout();
        initTabelyout();
    }

    private void initTabelyout() {
        PagerAdapter adapter=new ViewPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    private void initDrawerLayout() {
        headview = navigationview.getHeaderView(0);
        headview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplication(), "头像", Toast.LENGTH_LONG).show();
            }
        });
        navigationview.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menu_menu_app_update:
                        Toast.makeText(getApplication(), "啦啦啦", Toast.LENGTH_LONG).show();
                        break;
                }
                return false;
            }
        });
        toolbar.inflateMenu(R.menu.toolbar_menu);
        //toolbar怎么和DrawerLayout整合起来
        ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, drawlayout, toolbar, R.string.open, R.string.close);
        //接下来对DrawerLayout的监听事件重新实现
        mDrawerToggle.syncState();
        drawlayout.addDrawerListener(mDrawerToggle);
    }

}
